package com.spring.shops.admin.controller.product;

import com.spring.shops.model.entity.ProdProp1;
import com.spring.shops.model.entity.TzProdPropValue;
import com.spring.shops.model.result.ProdPropResult;
import com.spring.shops.model.vo.ProdPropVO;
import com.spring.shops.service.ProdPropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/prod/spec")

public class ProdPropController {
    @Autowired
    private ProdPropService prodPropService;

    @ResponseBody
    @GetMapping("/page")
    public ProdPropResult page(@RequestParam("current") String current,
                               @RequestParam("size") String size,
                               @RequestParam(value="propName", defaultValue="") String propName){

        ProdPropVO vo = new ProdPropVO();
        vo.setCurrent(current);
        vo.setSize(size);
        ProdPropVO page = prodPropService.getPage(vo, propName);
        return ProdPropResult.page(page);
    }
    @ResponseBody
    @PostMapping
    public  ProdPropResult save( @RequestBody ProdProp1 prodProp1){
        prodProp1.setRule((byte)1);
        prodProp1.setShopId((long)1);
        prodPropService.save(prodProp1);
        return ProdPropResult.Success();
    }
    @ResponseBody
    @DeleteMapping("/{id}")
    public ProdPropResult delete(@PathVariable Long id){
        prodPropService.deleted(id);
        return ProdPropResult.Success();
    }

   // @GetMapping("/listSpecValue/{specId}")
    @ResponseBody
    public ProdPropResult getList(@PathVariable Long specId){
         TzProdPropValue tzProdPropValues = prodPropService.selectBySpecId(specId);

        return ProdPropResult.infoResult(tzProdPropValues);
    }
    @ResponseBody
    @PutMapping
    public ProdPropResult update(@RequestBody ProdProp1 prodProp1){

        System.out.println(prodProp1.getProdPropValues().size());
        prodPropService.update(prodProp1);
        return ProdPropResult.Success();


    }




}
